package com.test.reactor.mq.rocket;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;

import lombok.extern.slf4j.Slf4j;

import java.util.List;
/**
 * @author: 
 * @Date: 19:29 2019/1/15
 */
@Slf4j
public class MessageListen implements MessageListenerConcurrently {
    private String  name;
    public MessageListen(String name) {
        this.name = name;
    }

    @Override
    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
        MessageExt messageExt = list.get(0);
        
      //这里收到的body（也就是消息体）是字节类型，转为String
        String result = new String(messageExt.getBody());
        log.info("**"+name+"**---" + messageExt.getMsgId() + "  " +messageExt.getReconsumeTimes() + " 收到了消息："+ result);
        
//        return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }
}
